const app = getApp();
const util = require('../../../../utils/util.js');
const api = require('../../../../config/api.js');
Page({
  data: {
    selectPanel:0,//选择的浏览类型
    longTime: false,//是否查看更早的订单
    orderAllList: [
      { "title": "阅读的方式阅读的方式阅读的方式", "img": "https://image.xingqubaike.com:8443/minicard/ucenter/personcenter/background/scene/1.png", "state": 1, 'goodsData': [{ "orderNumber": "1702 2645 3561 4587", "sum": 2 }, { "orderNumber": "1702 2645 3561 2583", "sum": 1 }], 'dealTime': '2019.01.14', 'totalMoney': '9999' },
      { "title": "阅读的方式", "img": "https://image.xingqubaike.com:8443/minicard/ucenter/personcenter/background/scene/2.png", "state": 2, 'goodsData': [{ "orderNumber": "1702 2645 3561 4377", "sum": 1 }, { "orderNumber": "1702 2645 3561 2224", "sum": 1 }], 'dealTime': '2019.01.12', 'totalMoney': '19'},
      { "title": "阅读的方式", "img": "https://image.xingqubaike.com:8443/minicard/ucenter/personcenter/background/scene/3.png", "state": 3, 'goodsData': [{ "orderNumber": "1702 2645 3561 6666", "sum": 1 }], 'dealTime': '2019.01.10', 'totalMoney': '9999'},
      { "title": "阅读的方式", "img": "https://image.xingqubaike.com:8443/minicard/ucenter/personcenter/background/scene/4.png", "state": 4, 'goodsData': [{ "orderNumber": "1702 2645 3561 0000", "sum": 1 }], 'dealTime': '2019.01.09','totalMoney':'9999' }
    ],//全部订单数据
    orderInfoList: [],//页面展示的数据数组
  },
  onLoad: function (options) {

  },
  onShow: function(){
    var _this = this;
    var panel = _this.data.selectPanel;
    var allArr = _this.data.orderAllList;
    var arr = [];
    if(panel==0){
      _this.setData({
        orderInfoList: allArr
      })
    }
    if (panel == 1) {
      for(var i=0;i<allArr.length;i++){
        if (allArr[i].state==2){
          arr.push(allArr[i])
        }
      }
      _this.setData({
        orderInfoList: arr
      })
    }
    if (panel == 2) {
      for (var i = 0; i < allArr.length; i++) {
        if (allArr[i].state == 3 || allArr[i].state == 4) {
          arr.push(allArr[i])
        }
      }
      _this.setData({
        orderInfoList: arr
      })
    }
  },
  /**
   * 选择要浏览的模块
   */
  selectViewPanel: function(e){
    var _this = this
    var index = e.currentTarget.dataset.index;
    _this.setData({
      selectPanel: index
    })
    var allArr = _this.data.orderAllList;
    var arr = [];
    if (index == 0) {
      _this.setData({
        orderInfoList: allArr
      })
    }
    if (index == 1) {
      for (var i = 0; i < allArr.length; i++) {
        if (allArr[i].state == 2) {
          arr.push(allArr[i])
        }
      }
      _this.setData({
        orderInfoList: arr
      })
    }
    if (index == 2) {
      for (var i = 0; i < allArr.length; i++) {
        if (allArr[i].state == 3 || allArr[i].state == 4) {
          arr.push(allArr[i])
        }
      }
      _this.setData({
        orderInfoList: arr
      })
    }
  },
  /**
   * 查看全部订单
   */
  viewAllData: function(){
    var _this = this
    _this.setData({
      longTime: true
    })
    var allArr = _this.data.orderAllList;
    allArr.push({ "title": "阅读的方式阅读的方式阅读的方式", "img": "https://image.xingqubaike.com:8443/minicard/ucenter/personcenter/background/scene/1.png", "state": 1, 'goodsData': [{ "orderNumber": "1702 2645 3561 4587", "sum": 2 }, { "orderNumber": "1702 2645 3561 2583", "sum": 1 }], 'dealTime': '2019.01.04', 'totalMoney': '9999' },
      { "title": "阅读的方式", "img": "https://image.xingqubaike.com:8443/minicard/ucenter/personcenter/background/scene/2.png", "state": 2, 'goodsData': [{ "orderNumber": "1702 2645 3561 4377", "sum": 1 }, { "orderNumber": "1702 2645 3561 2224", "sum": 1 }], 'dealTime': '2019.01.03', 'totalMoney': '19' },
      { "title": "阅读的方式", "img": "https://image.xingqubaike.com:8443/minicard/ucenter/personcenter/background/scene/3.png", "state": 3, 'goodsData': [{ "orderNumber": "1702 2645 3561 6666", "sum": 1 }], 'dealTime': '2019.01.02', 'totalMoney': '9999' },
      { "title": "阅读的方式", "img": "https://image.xingqubaike.com:8443/minicard/ucenter/personcenter/background/scene/4.png", "state": 4, 'goodsData': [{ "orderNumber": "1702 2645 3561 0000", "sum": 1 }], 'dealTime': '2019.01.01', 'totalMoney': '9999' })
    _this.setData({
      orderAllList: allArr
    }) 
    _this.onShow();
  },
  /**
   * 进入订单详情
   */
  gotoOrder:function(){
    wx.navigateTo({
      url: '../order/order',
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
  },
})